package cn.jhc.sevlet;//按学号查找学生信息

import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jhc.bean.Student;
import cn.jhc.dao.StudentDao;
import cn.jhc.dao.impl.StudentDaoImpl;

/**
 * Servlet implementation class InfoSelectServlet
 */
@WebServlet("/user/teacher/infoselect.do")
public class InfoSelectServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public InfoSelectServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String spage = request.getParameter("page");
		int page = 1;
		try {
			page = Integer.valueOf(spage);
		} catch (NumberFormatException e) {
			page = 1;
		}
		String username = request.getParameter("username");
		StudentDao studentDao = new StudentDaoImpl();
//		Student student = studentDao.getStudent(username);
//		Set<Student> students = new HashSet<Student>();
//		if(student!=null){
//		students.add(student);
//		}
		int count = (int) studentDao.getCount();
		List<Student> students = studentDao.list(null, username, 10 * ( page - 1 ) , 10);
		long maxpage = students.size()/ 10 + 1;
		request.setAttribute("page", page);
		request.setAttribute("maxpage", maxpage);
		request.setAttribute("students", students);
		request.getRequestDispatcher("tinformation.jsp").forward(request,
				response);
		return;
	}

}
